<?php
namespace Common\Model;

Class HotelCheckinUsableModel extends BaseModel
{
    protected $trueTableName = 'bk_hotel_checkin_usable';
    protected $field = 'id,hotelentity_id,type';

    /**
     * @modify wenhui 2017-10-10 创建
     * @param  integer   $hotelId   客栈ID
     * @param  integer $type       状态
     * @return mixin        执行成功返回id
     */
    public function addInfo($hotelId, $type = null) {
        $data = array(
            'hotelentity_id' => $hotelId
        );

        if (!is_null($type)) {
            $data['type'] = $type;
        }

        $id = $this->add($data);
        return $id === false ? false : $id;
    }

    /**
     * 更改该客栈信息
     * @modify wenhui 2017-10-10 创建
     * @param  integer   $hotelId   客栈ID
     * @param  integer $type       状态
     * @return boolean true为修改成功，false为修改失败
     */
    public function saveInfo($hotelId, $type = null) {
        $option = array(
            'hotelentity_id' => $hotelId
        );
        $data = array();
        if (!is_null($type)) {
            $data['type'] = $type;
        }

        return $this->where($option)->save($data) === false ? false : true;
    }

    /**
     * @modify wenhui 2017-10-10 创建
     * @param  integer   $hotelId   客栈ID
     * @return mixin        执行成功返回id
     */
    public function getInfo($hotelId) {
        $option = array();
        if (is_array($hotelId)) {
            $hotelId = implode(',', $hotelId);
        }

        if (strpos($hotelId, ',') === false) {
            $option['hotelentity_id'] = $hotelId;
            $data = $this->field($this->field)->where($option)->find();            
        } else {
            $option['hotelentity_id'] = array('in', $hotelId);
            $data = $this->field($this->field)->where($option)->select();
        }

        return empty($data) ? array() : $data;
    }
}
